
********************************************************************************
**** CONVERT BOARDEX INTO A PANEL DATA WITH YEAR-DIRECTOR-FIRM OBSERVATIONS  
********************************************************************************

/*

1) This do-file gets the director individual information from BoardEx and then 
separates the sample into 50 subsamples to make the analysis faster.
2) Create a list of all firms in BoardEx and link between each Boardex firm ID 
and its gvkey (using historical CUSIP)
3) For each subsample, keeps only the individuals that are board members. 
Then, based on the start-date and end-date, the do-files creates a panel data 
with all the firm-director pairs.
4) Put together all the subsamples in one file called "boardex_empl.dta"

*/

cd "`c(pwd)'"   // Set working directory to wherever the user placed "replication_package"

* Define global paths relative to the main directory
global main_dir "`c(pwd)'"
global data_dir "$main_dir/data_analysis"
global rawdata_dir "$main_dir/data_raw"
global tables_dir "$main_dir/tables"

cd "$rawdata_dir/"

* 1)
* Starting with BoardEx INDIVIDUAL:
use boardex, clear
joinby directorid using boardex_indiv, unmatched(master)
rename _merge _merge_boardex_indiv_id
tab _merge_boardex_indiv_id
*joinby directorname using boardex_indiv, unmatched(master)
*rename _merge _merge_boardex_indiv_name
*tab _merge_boardex_indiv_name
*save boardex2.dta, replace
*/
* Separating the dataset in 50 samples to make the code faster:
*use boardex2, clear
gen id=_n
replace id=id/5761036
save boardex2, replace
keep if id<0.02
save boardex_02.dta, replace
use boardex2, clear
keep if id>=0.02 & id<0.04
save boardex_04.dta, replace
use boardex2, clear
keep if id>=0.04 & id<0.06
save boardex_06.dta, replace
use boardex2, clear
keep if id>=0.06 & id<0.08
save boardex_08.dta, replace
use boardex2, clear
keep if id>=0.08 & id<0.10
save boardex_10.dta, replace
use boardex2, clear
keep if id>=0.10 & id<0.12
save boardex_12.dta, replace
use boardex2, clear
keep if id>=0.12 & id<0.14
save boardex_14.dta, replace
use boardex2, clear
keep if id>=0.14 & id<0.16
save boardex_16.dta, replace
use boardex2, clear
keep if id>=0.16 & id<0.18
save boardex_18.dta, replace
use boardex2, clear
keep if id>=0.18 & id<0.20
save boardex_20.dta, replace
use boardex2, clear
keep if id>=0.20 & id<0.22
save boardex_22.dta, replace
use boardex2, clear
keep if id>=0.22 & id<0.24
save boardex_24.dta, replace
use boardex2, clear
keep if id>=0.24 & id<0.26
save boardex_26.dta, replace
use boardex2, clear
keep if id>=0.26 & id<0.28
save boardex_28.dta, replace
use boardex2, clear
keep if id>=0.28 & id<0.30
save boardex_30.dta, replace
use boardex2, clear
keep if id>=0.30 & id<0.32
save boardex_32.dta, replace
use boardex2, clear
keep if id>=0.32 & id<0.34
save boardex_34.dta, replace
use boardex2, clear
keep if id>=0.34 & id<0.36
save boardex_36.dta, replace
use boardex2, clear
keep if id>=0.36 & id<0.38
save boardex_38.dta, replace
use boardex2, clear
keep if id>=0.38 & id<0.40
save boardex_40.dta, replace
use boardex2, clear
keep if id>=0.40 & id<0.42
save boardex_42.dta, replace
use boardex2, clear
keep if id>=0.42 & id<0.44
save boardex_44.dta, replace
use boardex2, clear
keep if id>=0.44 & id<0.46
save boardex_46.dta, replace
use boardex2, clear
keep if id>=0.46 & id<0.48
save boardex_48.dta, replace
use boardex2, clear
keep if id>=0.48 & id<0.50
save boardex_50.dta, replace
use boardex2, clear
keep if id>=0.50 & id<0.52
save boardex_52.dta, replace
use boardex2, clear
keep if id>=0.52 & id<0.54
save boardex_54.dta, replace
use boardex2, clear
keep if id>=0.54 & id<0.56
save boardex_56.dta, replace
use boardex2, clear
keep if id>=0.56 & id<0.58
save boardex_58.dta, replace
use boardex2, clear
keep if id>=0.58 & id<0.60
save boardex_60.dta, replace
use boardex2, clear
keep if id>=0.60 & id<0.62
save boardex_62.dta, replace
use boardex2, clear
keep if id>=0.62 & id<0.64
save boardex_64.dta, replace
use boardex2, clear
keep if id>=0.64 & id<0.66
save boardex_66.dta, replace
use boardex2, clear
keep if id>=0.66 & id<0.68
save boardex_68.dta, replace
use boardex2, clear
keep if id>=0.68 & id<0.70
save boardex_70.dta, replace
use boardex2, clear
keep if id>=0.70 & id<0.72
save boardex_72.dta, replace
use boardex2, clear
keep if id>=0.72 & id<0.74
save boardex_74.dta, replace
use boardex2, clear
keep if id>=0.74 & id<0.76
save boardex_76.dta, replace
use boardex2, clear
keep if id>=0.76 & id<0.78
save boardex_78.dta, replace
use boardex2, clear
keep if id>=0.78 & id<0.80
save boardex_80.dta, replace
use boardex2, clear
keep if id>=0.80 & id<0.82
save boardex_82.dta, replace
use boardex2, clear
keep if id>=0.82 & id<0.84
save boardex_84.dta, replace
use boardex2, clear
keep if id>=0.84 & id<0.86
save boardex_86.dta, replace
use boardex2, clear
keep if id>=0.86 & id<0.88
save boardex_88.dta, replace
use boardex2, clear
keep if id>=0.88 & id<0.90
save boardex_90.dta, replace
use boardex2, clear
keep if id>=0.90 & id<0.92
save boardex_92.dta, replace
use boardex2, clear
keep if id>=0.92 & id<0.94
save boardex_94.dta, replace
use boardex2, clear
keep if id>=0.94 & id<0.96
save boardex_96.dta, replace
use boardex2, clear
keep if id>=0.96 & id<0.98
save boardex_98.dta, replace
use boardex2, clear
keep if id>=0.98 
save boardex_100.dta, replace

*/
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************

* 2) LINK WITH GVKEY

* 1) create list of firms. Form ISIN extract CUSIP8 (CRSP CUSIP). 
use boardex, clear
keep companyname companyid isin dateendrole
gen year=year(dateendrole)
drop dateendrole
replace year=2020 if year==.
sort companyid year isin
drop if companyid==companyid[_n-1] & year==year[_n-1]
gen countrycode=substr(isin,1,2)
keep if countrycode=="US"
gen cusip1=substr(isin,3,11)
gen cusip=substr(cusip1,1,8)
joinby cusip year using CRSP_Hist_Cusips, unmatched(master)
drop _merge
joinby permno year using compustat_permno_gvkey, unmatched(master)
tab _merge
drop _merge
drop if gvkey==.
keep companyid year gvkey companyname
save boardex_cusip_gvkey, replace


********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************

* 3)

use boardex_02
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_02.dta, replace

********************************************************************************
use boardex_04
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_04.dta, replace

********************************************************************************
use boardex_06
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_06.dta, replace

********************************************************************************
use boardex_08
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_08.dta, replace

********************************************************************************
use boardex_10
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_10.dta, replace

********************************************************************************
use boardex_12
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_12.dta, replace

********************************************************************************
use boardex_14
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_14.dta, replace

********************************************************************************
use boardex_16
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_16.dta, replace

********************************************************************************
use boardex_18
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_18.dta, replace

********************************************************************************
use boardex_20
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_20.dta, replace

********************************************************************************
use boardex_22
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_22.dta, replace

********************************************************************************
use boardex_24
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_24.dta, replace

********************************************************************************
use boardex_26
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_26.dta, replace

********************************************************************************
use boardex_28
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_28.dta, replace

********************************************************************************
use boardex_30
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_30.dta, replace

********************************************************************************
use boardex_32
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_32.dta, replace

********************************************************************************
use boardex_34
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_34.dta, replace

********************************************************************************
use boardex_36
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_36.dta, replace

********************************************************************************
use boardex_38
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_38.dta, replace

********************************************************************************
use boardex_40
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_40.dta, replace

********************************************************************************
use boardex_42
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_42.dta, replace

********************************************************************************
use boardex_44
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_44.dta, replace

********************************************************************************
use boardex_46
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_46.dta, replace

********************************************************************************
use boardex_48
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_48.dta, replace

********************************************************************************
use boardex_50
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_50.dta, replace

********************************************************************************
use boardex_52
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_52.dta, replace

********************************************************************************
use boardex_54
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_54.dta, replace

********************************************************************************
use boardex_56
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_56.dta, replace

********************************************************************************
use boardex_58
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_58.dta, replace

********************************************************************************
use boardex_60
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_60.dta, replace

********************************************************************************
use boardex_62
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_62.dta, replace

********************************************************************************
use boardex_64
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_64.dta, replace

********************************************************************************
use boardex_66
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_66.dta, replace

********************************************************************************
use boardex_68
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_68.dta, replace

********************************************************************************
use boardex_70
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_70.dta, replace

********************************************************************************
use boardex_72
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_72.dta, replace

********************************************************************************
use boardex_74
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_74.dta, replace

********************************************************************************
use boardex_76
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_76.dta, replace

********************************************************************************
use boardex_78
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_78.dta, replace

********************************************************************************
use boardex_80
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_80.dta, replace

********************************************************************************
use boardex_82
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_82.dta, replace

********************************************************************************
use boardex_84
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_84.dta, replace

********************************************************************************
use boardex_86
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_86.dta, replace

********************************************************************************
use boardex_88
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_88.dta, replace

********************************************************************************
use boardex_90
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_90.dta, replace

********************************************************************************
use boardex_92
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_92.dta, replace

********************************************************************************
use boardex_94
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_94.dta, replace

********************************************************************************
use boardex_96
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_96.dta, replace

********************************************************************************
use boardex_98
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_98.dta, replace

********************************************************************************
use boardex_100
drop if brdposition=="No"
drop if companyid==.
drop if directorid==.
gen startyear = year(datestartrole) 
gen endyear =  year(dateendrole)
replace endyear=2019 if  endyear==. & startyear<=2019
sum  startyear endyear
drop if endyear<1989
gen y1989=1 if startyear<=1989 & endyear>=1989 
gen y1990=1 if startyear<=1990 & endyear>=1990 
gen y1991=1 if startyear<=1991 & endyear>=1991 
gen y1992=1 if startyear<=1992 & endyear>=1992 
gen y1993=1 if startyear<=1993 & endyear>=1993 
gen y1994=1 if startyear<=1994 & endyear>=1994 
gen y1995=1 if startyear<=1995 & endyear>=1995
gen y1996=1 if startyear<=1996 & endyear>=1996 
gen y1997=1 if startyear<=1997 & endyear>=1997 
gen y1998=1 if startyear<=1998 & endyear>=1998 
gen y1999=1 if startyear<=1999 & endyear>=1999 
gen y2000=1 if startyear<=2000 & endyear>=2000 
gen y2001=1 if startyear<=2001 & endyear>=2001 
gen y2002=1 if startyear<=2002 & endyear>=2002 
gen y2003=1 if startyear<=2003 & endyear>=2003 
gen y2004=1 if startyear<=2004 & endyear>=2004 
gen y2005=1 if startyear<=2005 & endyear>=2005 
gen y2006=1 if startyear<=2006 & endyear>=2006 
gen y2007=1 if startyear<=2007 & endyear>=2007 
gen y2008=1 if startyear<=2008 & endyear>=2008 
gen y2009=1 if startyear<=2009 & endyear>=2009 
gen y2010=1 if startyear<=2010 & endyear>=2010 
gen y2011=1 if startyear<=2011 & endyear>=2011 
gen y2012=1 if startyear<=2012 & endyear>=2012 
gen y2013=1 if startyear<=2013 & endyear>=2013 
gen y2014=1 if startyear<=2014 & endyear>=2014 
gen y2015=1 if startyear<=2015 & endyear>=2015 
gen y2016=1 if startyear<=2016 & endyear>=2016 
gen y2017=1 if startyear<=2017 & endyear>=2017 
gen y2018=1 if startyear<=2018 & endyear>=2018 
gen y2019=1 if startyear<=2019 & endyear>=2019 
collapse (sum)  y1989 y1990 y1991 y1992 y1993 y1994 y1995 y1996 y1997 y1998 y1999 y2000 y2001 y2002 y2003 y2004 y2005 y2006 y2007 y2008 y2009 y2010 y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019  , by(directorid companyid)
replace y1989=companyid if y1989>=1
replace y1990=companyid if y1990>=1
replace y1991=companyid if y1991>=1
replace y1992=companyid if y1992>=1
replace y1993=companyid if y1993>=1
replace y1994=companyid if y1994>=1
replace y1995=companyid if y1995>=1
replace y1996=companyid if y1996>=1
replace y1997=companyid if y1997>=1
replace y1998=companyid if y1998>=1
replace y1999=companyid if y1999>=1
replace y2000=companyid if y2000>=1
replace y2001=companyid if y2001>=1
replace y2002=companyid if y2002>=1
replace y2003=companyid if y2003>=1
replace y2004=companyid if y2004>=1
replace y2005=companyid if y2005>=1
replace y2006=companyid if y2006>=1
replace y2007=companyid if y2007>=1
replace y2008=companyid if y2008>=1
replace y2009=companyid if y2009>=1
replace y2010=companyid if y2010>=1
replace y2011=companyid if y2011>=1
replace y2012=companyid if y2012>=1
replace y2013=companyid if y2013>=1
replace y2014=companyid if y2014>=1
replace y2015=companyid if y2015>=1
replace y2016=companyid if y2016>=1
replace y2017=companyid if y2017>=1
replace y2018=companyid if y2018>=1
replace y2019=companyid if y2019>=1
sort directorid companyid
reshape long y, i(directorid companyid)
rename _j year
drop companyid
rename y companyid
drop if companyid==0
joinby companyid year using boardex_cusip_gvkey, unmatched(master)
drop _merge
drop if gvkey==.
save boardex_empl_100.dta, replace

********************************************************************************
********************************************************************************
********************************************************************************

* 4) ALL TOGETHER *******
use boardex_empl_02
append using boardex_empl_04
append using boardex_empl_06
append using boardex_empl_08
append using boardex_empl_10
append using boardex_empl_12
append using boardex_empl_14
append using boardex_empl_16
append using boardex_empl_18
append using boardex_empl_20
append using boardex_empl_22
append using boardex_empl_24
append using boardex_empl_26
append using boardex_empl_28
append using boardex_empl_30
append using boardex_empl_32
append using boardex_empl_34
append using boardex_empl_36
append using boardex_empl_38
append using boardex_empl_40
append using boardex_empl_42
append using boardex_empl_44
append using boardex_empl_46
append using boardex_empl_48
append using boardex_empl_50
append using boardex_empl_52
append using boardex_empl_54
append using boardex_empl_56
append using boardex_empl_58
append using boardex_empl_60
append using boardex_empl_62
append using boardex_empl_64
append using boardex_empl_66
append using boardex_empl_68
append using boardex_empl_70
append using boardex_empl_72
append using boardex_empl_74
append using boardex_empl_76
append using boardex_empl_78
append using boardex_empl_80
append using boardex_empl_82
append using boardex_empl_84
append using boardex_empl_86
append using boardex_empl_88
append using boardex_empl_90
append using boardex_empl_92
append using boardex_empl_94
append using boardex_empl_96
append using boardex_empl_98
append using boardex_empl_100

cd "$data_dir/"
save boardex_empl.dta, replace



***************
***************
***************
***************
***************
***************
***************
***************
***************




